import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;


public class Server {

    public static void main(String[] args) {
        ServerSocket serverSocket = null;
        Socket socket = null;
        BufferedReader in = null;
        BufferedReader sin = null;
        PrintWriter out = null;
        String line = "";

        try{
            serverSocket = new ServerSocket(4700);
        }catch(IOException e){
            e.printStackTrace();
        }



        try{
            socket = serverSocket.accept();
        }catch(IOException E){
            System.out.println("can't connect the server");
            E.printStackTrace();
        }



        try {
            sin = new BufferedReader(new InputStreamReader(System.in));
            in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            out = new PrintWriter(socket.getOutputStream());

            //
            System.out.println("the server accept data:\t"+in.readLine());
            line = sin.readLine();
            while(!line.equalsIgnoreCase("bye")){
                out.println(line);
                out.flush();
                System.out.println("server send data:\t"+line);
                System.out.println("server accept date:\t"+in.readLine());  
                line = sin.readLine();

            }

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }




    }

}